home *** CD-ROM | disk | FTP | other *** search
- package
- {
- import Common.SoundManager;
- import flash.display.DisplayObject;
- import flash.display.DisplayObjectContainer;
- import flash.display.MovieClip;
- import flash.events.Event;
- import flash.events.EventDispatcher;
- import flash.events.MouseEvent;
- import flash.geom.Point;
- import flash.media.SoundChannel;
- import flash.text.TextField;
-
- public class DressupEngine extends EventDispatcher
- {
-
- public static const DressupEnginePickup:String = "DressupEnginePickup";
-
- public static const DressupEngineDrop:String = "DressupEngineDrop";
-
-
- public var DebugText:TextField = null;
-
- internal var _aslots:Array;
-
- public var AlwaysActive:* = true;
-
- internal var _amodels:Array;
-
- internal var _partCurrent:Part = null;
-
- internal var _modelActive:Model = null;
-
- internal var _bPickup:Boolean = true;
-
- internal var _scVoiceOvers:SoundChannel = null;
-
- internal var _bEnabled:Boolean = true;
-
- internal var _doc:DisplayObjectContainer;
-
- internal var _pCurrentOffset:Point;
-
- public function DressupEngine(param1:DisplayObjectContainer, param2:Array, param3:Array)
- {
- var _loc4_:DisplayObject = null;
- AlwaysActive = true;
- _bEnabled = true;
- _bPickup = true;
- _amodels = new Array();
- _aslots = new Array();
- _partCurrent = null;
- _pCurrentOffset = new Point();
- DebugText = null;
- _modelActive = null;
- _scVoiceOvers = null;
- super();
- _doc = param1;
- _aslots = param2;
- _amodels = param3;
- _doc.addEventListener(MouseEvent.MOUSE_MOVE,onMouseMove,false,0,true);
- for each(_loc4_ in _aslots)
- {
- _loc4_.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown,false,0,true);
- }
- for each(_loc4_ in _amodels)
- {
- _loc4_.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDown,false,0,true);
- }
- ActiveModel = _amodels[0];
- }
-
- internal function onPickupClothes() : void
- {
- SoundManager.getInstance().playSound("PickupItemSound");
- dispatchEvent(new Event(DressupEnginePickup));
- }
-
- public function get Enabled() : Boolean
- {
- return _bEnabled;
- }
-
- public function get ActiveModel() : Model
- {
- return _modelActive;
- }
-
- protected function returnCurrent() : void
- {
- if(_partCurrent != null)
- {
- _doc.removeChild(_partCurrent);
- reslotPart(_partCurrent);
- _partCurrent = null;
- }
- }
-
- protected function setCurrent(param1:Part) : void
- {
- _partCurrent = param1;
- _pCurrentOffset = new Point(-_partCurrent.width / 2,-_partCurrent.height / 2);
- _partCurrent.Pose = ModelPose.DEFAULT;
- _partCurrent.x = _doc.mouseX + _pCurrentOffset.x;
- _partCurrent.y = _doc.mouseY + _pCurrentOffset.y;
- _doc.addChild(_partCurrent);
- }
-
- protected function playPutClothingSoundFor(param1:Model) : void
- {
- if(param1.name.indexOf("model1") >= 0)
- {
- SoundManager.getInstance().playSound("PutClothingSound1");
- FeedbackClothes((param1 as DressupModel).ModelTheme);
- }
- else if(param1.name.indexOf("model0") >= 0)
- {
- SoundManager.getInstance().playSound("PutClothingSound2");
- FeedbackClothes((param1 as DressupModel).ModelTheme);
- }
- else if(param1.name.indexOf("model2") >= 0)
- {
- SoundManager.getInstance().playSound("PutClothingSound3");
- FeedbackClothes((param1 as DressupModel).ModelTheme);
- }
- else
- {
- SoundManager.getInstance().playSound("PutClothingSound1");
- }
- }
-
- public function set Pickup(param1:Boolean) : void
- {
- _bPickup = param1;
- }
-
- public function set Enabled(param1:Boolean) : void
- {
- _bEnabled = param1;
- }
-
- public function stopVoiceOver() : void
- {
- if(_scVoiceOvers != null)
- {
- _scVoiceOvers.stop();
- }
- }
-
- public function set ActiveModel(param1:Model) : *
- {
- deactivateAllModels();
- _modelActive = param1;
- _modelActive.Active = true;
- }
-
- protected function onMouseDown(param1:MouseEvent) : void
- {
- var _loc2_:Boolean = false;
- var _loc3_:Boolean = false;
- var _loc4_:ClothingSlot = null;
- var _loc5_:Part = null;
- var _loc6_:int = 0;
- var _loc7_:Model = null;
- var _loc8_:Part = null;
- var _loc9_:Part = null;
- _loc2_ = false;
- _loc3_ = false;
- _loc6_ = 0;
- while(_loc6_ < _aslots.length)
- {
- if((_loc4_ = _aslots[_loc6_] as ClothingSlot).getBounds(_doc).containsPoint(new Point(_doc.mouseX,_doc.mouseY)))
- {
- _loc2_ = true;
- _loc8_ = null;
- if(_loc4_.hasPart() && _partCurrent == null)
- {
- if(_loc4_.getPart().hasPixel(_doc.mouseX,_doc.mouseY,_doc))
- {
- if(_bPickup)
- {
- _loc8_ = _loc4_.pickupPart();
- }
- else if((_loc8_ = _loc4_.getPart()) != null)
- {
- _loc8_ = _loc8_.Template.createPart();
- }
- }
- else if(_loc4_.getPart().Category == "body")
- {
- if((_loc8_ = _loc4_.getPart()) != null)
- {
- _loc8_ = _loc8_.Template.createPart();
- }
- }
- }
- if(_loc8_ != null)
- {
- _loc8_.x = _doc.mouseX + _pCurrentOffset.x;
- _loc8_.y = _doc.mouseY + _pCurrentOffset.y;
- if(_partCurrent != null)
- {
- returnCurrent();
- setCurrent(_loc8_);
- _loc3_ = true;
- }
- else if(_loc8_ != _partCurrent)
- {
- returnCurrent();
- setCurrent(_loc8_);
- _loc3_ = true;
- }
- else
- {
- returnCurrent();
- _loc3_ = true;
- }
- break;
- }
- if(_partCurrent != null)
- {
- break;
- }
- }
- _loc6_++;
- }
- if(_loc2_ && !_loc3_ && _partCurrent != null)
- {
- onDropClothes();
- returnCurrent();
- }
- if(_loc3_)
- {
- onPickupClothes();
- }
- for each(_loc7_ in _amodels)
- {
- if(Boolean(_loc7_.getBounds(_doc).containsPoint(new Point(_doc.mouseX,_doc.mouseY))) && _loc7_.visible)
- {
- if(_loc7_.Active || AlwaysActive)
- {
- ActiveModel = _loc7_;
- if(_partCurrent != null)
- {
- _loc5_ = _loc7_.removePart(_partCurrent.Category);
- reslotPart(_loc5_);
- if(_partCurrent.Category == "dress")
- {
- _loc5_ = _loc7_.removePart("top");
- reslotPart(_loc5_);
- _loc5_ = _loc7_.removePart("bottom");
- reslotPart(_loc5_);
- }
- else if(_partCurrent.Category == "bottom")
- {
- _loc5_ = _loc7_.removePart("dress");
- reslotPart(_loc5_);
- }
- else if(_partCurrent.Category == "top")
- {
- _loc5_ = _loc7_.removePart("dress");
- reslotPart(_loc5_);
- }
- _loc7_.addPart(_partCurrent);
- playPutClothingSoundFor(_loc7_);
- onDropClothes();
- _partCurrent = null;
- }
- else
- {
- _partCurrent = _loc7_.pickupPart(new Point(_doc.mouseX,_doc.mouseY),_doc);
- if(_partCurrent != null)
- {
- onPickupClothes();
- setCurrent(_partCurrent);
- }
- }
- }
- else
- {
- ActiveModel = _loc7_;
- }
- }
- }
- if(_partCurrent != null && DebugText != null)
- {
- DebugText.text = _partCurrent.Template.Name;
- }
- }
-
- public function reslotPart(param1:Part) : ClothingSlot
- {
- var _loc2_:ClothingSlot = null;
- var _loc3_:String = null;
- _loc2_ = null;
- if(param1 != null)
- {
- _loc3_ = param1.Category;
- if(_loc3_ == "dress")
- {
- _loc3_ = "top";
- }
- for each(_loc2_ in _aslots)
- {
- if(!_loc2_.hasPart() && _loc2_.name.indexOf(_loc3_) != -1)
- {
- param1.Pose = ModelPose.DEFAULT;
- _loc2_.addChild(param1);
- param1.center();
- break;
- }
- }
- }
- return _loc2_;
- }
-
- protected function getPartFromSlot(param1:MovieClip) : Part
- {
- var _loc2_:int = 0;
- var _loc3_:Part = null;
- _loc2_ = 0;
- while(_loc2_ < param1.numChildren)
- {
- if(param1.getChildAt(_loc2_) is Part)
- {
- return param1.getChildAt(_loc2_) as Part;
- }
- _loc2_++;
- }
- return null;
- }
-
- internal function FeedbackClothes(param1:DressupTheme) : void
- {
- var _loc2_:Part = null;
- var _loc3_:int = 0;
- var _loc4_:String = null;
- var _loc5_:String = null;
- _loc2_ = _partCurrent;
- _loc3_ = 0;
- if(_loc2_ != null && param1 != null)
- {
- for each(_loc4_ in param1.TargetAttributes)
- {
- if(param1.Title.toLowerCase().indexOf(_loc4_.toLowerCase()) < 0)
- {
- if(_loc2_.Template.hasAttribute(_loc4_))
- {
- _loc3_++;
- }
- }
- }
- if(MainDocument.VOICE_OVERS_ENABLED)
- {
- if(_loc3_ > 4)
- {
- _loc5_ = "positive_" + int(Math.random() * 20 + 1);
- if(_scVoiceOvers != null)
- {
- _scVoiceOvers.stop();
- }
- _scVoiceOvers = SoundManager.getInstance().playSound(_loc5_);
- }
- if(_loc3_ == 0)
- {
- _loc5_ = "negative_" + int(Math.random() * 14 + 1);
- if(_scVoiceOvers != null)
- {
- _scVoiceOvers.stop();
- }
- _scVoiceOvers = SoundManager.getInstance().playSound(_loc5_);
- }
- }
- }
- }
-
- public function deactivateAllModels() : void
- {
- var _loc1_:Model = null;
- for each(_loc1_ in _amodels)
- {
- _loc1_.Active = false;
- }
- }
-
- public function removeDuplicates() : void
- {
- var _loc1_:Boolean = false;
- var _loc2_:int = 0;
- var _loc3_:int = 0;
- var _loc4_:ClothingSlot = null;
- var _loc5_:ClothingSlot = null;
- var _loc6_:String = null;
- _loc1_ = true;
- while(_loc1_)
- {
- _loc1_ = false;
- _loc2_ = 1;
- while(_loc2_ < this._aslots.length)
- {
- _loc4_ = _aslots[_loc2_] as ClothingSlot;
- _loc3_ = 0;
- while(_loc3_ < _loc2_)
- {
- _loc5_ = _aslots[_loc3_] as ClothingSlot;
- if(_loc4_.hasPart() && _loc5_.hasPart())
- {
- if(_loc4_.getPart().Template == _loc5_.getPart().Template)
- {
- _loc6_ = _loc5_.getPart().Template.Category;
- _loc5_.clean();
- _loc5_.addChild(MainDocument.Package.getRandomTemplate(_loc6_).createPart());
- _loc1_ = true;
- }
- }
- _loc3_++;
- }
- _loc2_++;
- }
- }
- }
-
- protected function onMouseMove(param1:MouseEvent) : void
- {
- if(_partCurrent != null)
- {
- _partCurrent.x = _doc.mouseX + _pCurrentOffset.x;
- _partCurrent.y = _doc.mouseY + _pCurrentOffset.y;
- }
- }
-
- internal function onDropClothes() : void
- {
- SoundManager.getInstance().playSound("PickupItemSound");
- dispatchEvent(new Event(DressupEngineDrop));
- }
- }
- }
-